package com.gk.sparsearray

import scala.collection.mutable.ArrayBuffer

/**
 *
 * @Author poison
 * @Date 2020/10/28 9:51
 */
object SparseTest1 {

  def main(args: Array[String]): Unit = {
    val rowSize = 11
    val colSize = 11
    val map = Array.ofDim[Int](11,11)
    // 初始化地图
    map(1)(2) = 1
    map(2)(3) = 2

    for(item <- map){
      print(item(2))
    }

    println
    println("------------------------------------------")

    for(item <- map){
      for(item2 <- item){
        printf("%d\t",item2)
      }
      println()
    }

    // 稀疏数组
    val sparseArray = ArrayBuffer[Node]()
    val Node = ()
    for (i<-0 until map.length){
      for(j<-0 until map(i).length){
        if(map(i)(j)!=0){
          val node = new Node(i,j,map(i)(j))
          sparseArray.append(node)
        }
      }
    }

    for(node<-sparseArray){
      printf("%d\t%d\t%d",node.row,node.col,node.value)
      println()
    }

    // 解析压缩数组

  }
}

